#include "Catch2.v3/catch_amalgamated.hpp"
#include "NetWork/HttpRequest.h"

#include <iostream>
#include <regex>

TEST_CASE("NetWork::HttpRequest"){
    const char* str = "hello \r world";
    const char* str1 = "hello \n world";
    const char* str2 = "hello \r\n world";

    std::cout << "str: " << str << std::endl;
    std::cout << "str1: " << str1 << std::endl;
    std::cout << "str2: " << str2 << std::endl;

    std::string str3("abcdefg\r\nhijklmn");
    std::cout << str3.find("\r\n") << std::endl;
    std::cout << str3.find_last_of("\r\n") << std::endl;
    std::cout << str3.substr(0, str3.find("\r\n")) << std::endl;

    std::string kv("a : b, c:d");
    std::regex reg(" ?: ?");

    //-1表示对于匹配的正则表达式之前的子序列感兴趣
    //而若指定0，则表示对于匹配的正则表达式感兴趣，这里就会得到 ":"
    std::sregex_token_iterator it(kv.begin(), kv.end(), reg, -1);

    decltype(it) end;

    for (; it != end; it++)
        std::cout << it->str() << std::endl;

    std::string request = "GET / HTTP/1.1\r\n"
    "Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9\r\n"
    "Accept-Encoding: gzip, deflate, br\r\n"
    "Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6\r\n"
    "Connection: keep-alive\r\n"
    "Host: www.baidu.com\r\n"
    "Sec-Fetch-Dest: document\r\n"
    "Sec-Fetch-Mode: navigate\r\n"
    "Sec-Fetch-Site: none\r\n"
    "Sec-Fetch-User: ?1\r\n"
    "Upgrade-Insecure-Requests: 1"
    "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.41 Safari/537.36 Edg/101.0.1210.32\r\n"
    "sec-ch-ua: \" Not A;Brand\";v=\"99\", \"Chromium\";v=\"101\", \"Microsoft Edge\";v=\"101\"\r\n"
    "sec-ch-ua-mobile: ?0\r\n"
    "sec-ch-ua-platform: \"Windows\"\r\n"
    "\r\n"
    "abcedfg";

    NetWork::HttpRequest httprequest;
    httprequest.Parse(request.c_str(), request.size());
}